In [3]:
# -*- coding: utf-8 -*-
#journals.py
"""Journals are particular kind of publication.
They have different publications in them by different authors.
Journals are periodical. Journals are made by publishers. Authors publish
in journals. Journals contain articles. Journals have associated editors.
Journals have.
There is a limited number of journals we have interest. For know we can
separated two groups of journals. First group of journals contain
interesting theoretical claims that we base our research on. Second
group of journals are mor einterested as a source of data.
First group consist of around 50 journals.
Second group is way larger.
"""
class Journal():
__self__ = ''
editors = []
publications = []
volumes = None
established = 'timestamp'
authors_who_published = []
journals_that_cited_this_journal = []
s4 = Journal
import pandas as pd
url = r'd:\Documents\GitHub\disciplines\disciplines\data\xlsx\sts books and journals.xlsx'
df = pd.read_excel(url, header=None )
df.columns = ['name', 'url']
In [4]:
# -*- coding: utf-8 -*-
#syllabi.py
source_url = r'http://www.4sonline.org/resources/syllabi'
url = r'd:\Documents\GitHub\disciplines\disciplines\data\xlsx\sts syllabi.xlsx'
df = pd.read_excel(url, header=0 )
In [5]:
df
Out[5]:
In [12]:
#system pip install mechanize
#system pip install python-docx
import mechanize
import docx
br = mechanize.Browser()
haha = br.open('http://www.4sonline.org/syllabi/Balmer1.doc')
document = docx.Document(haha.content)
#document.paragraphs
Delarative
In [1]:
#sqlalchemy
from sqlalchemy import *
from sqlalchemy import create_engine, Table, Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.engine.url import URL
DeclarativeBase = declarative_base()
engine = create_engine('sqlite:///:memory:', echo=True)
#metadata = MetaData()
class Disciplines(DeclarativeBase):
"""Disciplines"""
__tablename__ = "disciplines"
id = Column(Integer, primary_key=True)
name = Column('name', String)
description = Column('description', String, nullable=True)
link = Column('link', String, nullable=True)
# subdisciplines = relationship('subdisciplines', backref="disciplines")
# classifications = relationship('classifications', backref="disciplines")
class Classifications(DeclarativeBase):
"""Classifications"""
__tablename__ = "classifications"
id = Column(Integer, primary_key=True)
name = Column('name', String)
description = Column('description', String, nullable=True)
link = Column('link', String, nullable=True)
# author = relationship('persons', backref="classifications")
class Learned_societies(DeclarativeBase):
"""Learned_societies"""
__tablename__ = "learned societies"
id = Column(Integer, primary_key=True)
name = Column('name', String)
description = Column('description', String, nullable=True)
link = Column('link', String, nullable=True)
# members = relationship('persons', ForeignKey('learned_societies'))
class Persons(DeclarativeBase):
"""Persons"""
__tablename__ = "persons"
id = Column(Integer, primary_key=True)
name = Column('name', String)
first_name = Column('first_name', String)
last_name = Column('last_name', String)
link = Column('link', String, nullable=True)
# learned_societies = relationship('persons', ForeignKey('persons.id'))
class Concepts(DeclarativeBase):
"""Concepts"""
__tablename__ = "concepts"
id = Column(Integer, primary_key=True)
name = Column('name', String)
definition = Column('definition', String, nullable=True)
link = Column('link', String, nullable=True)
# definition = relationship('definitions', backref="parent")
class Definitions(DeclarativeBase):
"""Definitions"""
__tablename__ = "definitions"
id = Column(Integer, primary_key=True)
name = Column('name', String)
class Publications(DeclarativeBase):
"""Publications"""
__tablename__ = "publications"
id = Column(Integer, primary_key=True)
title = Column('title', String)
description = Column('description', String, nullable=True)
link = Column('link', String, nullable=True)
original_price = Column('original_price', String, nullable=True)
price = Column('price', String, nullable=True)
DeclarativeBase.metadata.create_all(engine)
In [4]:
from sqlalchemy.orm import sessionmaker
Session = sessionmaker(bind=engine)
session = Session()
tables = [Disciplines, Persons, Definitions, Publications, Learned_societies]
for x in tables:
q = session.query(x)
print q.column_descriptions
In [16]:
In [15]:
discipline = Disciplines(name='philosophy', description='The description')
discipline1 = Disciplines(name='sociology')
session.add(discipline)
session.add(discipline1)
session.commit()
session.add_all([Disciplines(name='physics', description='The description')])
session.commit()
In [35]:
from sqlalchemy.sql import expression
expression.delete(Disciplines, whereclause='name' is 'philosophy')
Out[35]:
In [41]:
from sqlalchemy import update
Disciplines.update().values(
name=select(['philosophy']).\
where(addresses.c.user_id==users.c.id).\
as_scalar())
In [47]:
from sqlalchemy.sql import Insert
Insert(table, values=None, inline=False, bind=None, prefixes=None, returning=None, **kwargs)
In [64]:
engine = create_engine('sqlite:///:memory:')
metadata = MetaData()
user = Table('user', metadata,
Column('user_id', Integer, primary_key = True),
Column('user_name', String(16), nullable = False),
Column('email_address', String(60), key='email'),
Column('password', String(20), nullable = False)
)
user_prefs = Table('user_prefs', metadata,
Column('pref_id', Integer, primary_key=True),
Column('user_id', Integer, ForeignKey("user.user_id"), nullable=False),
Column('pref_name', String(40), nullable=False),
Column('pref_value', String(100))
)
metadata.create_all(engine)
for t in metadata.sorted_tables:
print t.name
With some titles
In [16]:
url = r'd:\Desktop\medline11n0653.nq'
In [17]:
from rdflib import ConjunctiveGraph, URIRef, Namespace
In [18]:
g = ConjunctiveGraph()
data = open(url, "rb")
In [19]:
g.parse(data, format="nquads")
In [18]:
len(g)
g?
In [29]:
count = 0
for x,y,z in g:
count += 1
print x, y, z
if count == 50:
break
In [20]:
g.parse(data, format="nquads")
In [ ]: